﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace AutomaticProcess
{
    public partial class CCBAutomaticProcess : ServiceBase
    {
        public Timer tempo = new Timer();
        public CCBAutomaticProcess()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            try
            {

                System.Diagnostics.Debugger.Launch();

                tempo.Elapsed += tempo_Elapsed;
                tempo.Interval = 60000 * 1440;
                tempo.Enabled = true;
                
            }
            catch (Exception error)
            {

                throw new Exception("" + error.Message);
            }

        }

        void tempo_Elapsed(object sender, ElapsedEventArgs e)
        {
            VerificarSituacao();   
        }


        private void VerificarSituacao() 
        {
            try
            {
                    CCBWebService.VerificaOSClient objVerificaOS = new CCBWebService.VerificaOSClient();
                    objVerificaOS.GetOsComPrazoExperirado();
                    objVerificaOS.GetOsComVencimentoParaHoje();
                    objVerificaOS.GetOsComVencimentoParaUmaSemana();                    

            }
            catch (Exception error)
            {
                
                throw new Exception(""+error.Message);
            }
        }

        protected override void OnStop()
        {
            
        }
    }
}
